package com.example.yyy

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import org.jetbrains.anko.toast

/**
 * 循环视图适配器
 */
open abstract class RecyclerBaseAdapter<VH : RecyclerView.ViewHolder>(val context: Context) :
    RecyclerView.Adapter<RecyclerView.ViewHolder>(){
    protected val inflater:LayoutInflater = LayoutInflater.from(context)

    //根据布局文件创建视图持有者，需要子类重写
    abstract override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder

    //获取列表项的个数，需要子类重写
    abstract override fun getItemCount(): Int

    override fun getItemId(position: Int): Long =position.toLong()

    //绑定视图持有者中的各个控件对象，需要子类重写
    abstract override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int)

    override fun getItemViewType(position: Int): Int =0

}